<!--# layout("/common/layout.html",{"jsBase":"/js/${target.urlBase}/${entity.code}/"}){ -->

<form class="layui-form layui-form-pane" id="addForm" ${isEmpty(hasFile)?'':'enctype="multipart/form-data" '} lay-filter="editform">
    <input type="hidden" name="${idcol.name}" id="${idcol.name}">
    @ var list = entity.generalList;
	@ var size = list.~size; /*一行显示俩个，生成后在根据显示要求调整*/
	@ for(var i=0;i<size;i++){
	@ var item0=list[i];
	@ var item1=(size-i<=1)?null:list[i+1];
    @ var item2=(size-i<=2)?null:list[i+2];
	@ i=i+2;
	@ var array = [item0,item1,item2];

    <div class="layui-row">
        <div class="layui-form-item">
		@for(item in array){
			@if(item==null){continue;}
            @if(item.isId){continue;}
			@if(item.name=="delFlag"){continue;}
			@if(item.name=="version"){continue;}
			@if(item.name=="attachmentId"){continue;}
            <div class="layui-inline">
            <label class="layui-form-label">${item.displayName}</label>
				<div class="layui-input-inline">
                    @if(entity.pageType==2) {
                        <span style="line-height:38px;margin-left:8px">
                            \${${entity.code}.${item.name}}
                        </span>
                    @} else {
                    @if(entity.pageType==3) {
                        <span style="line-height:38px;margin-left:8px" id="${item.name}Span">
                            \${${entity.code}.${item.name}}
                        </span>
                    @}
					@if(isEmpty(item.dictType)){
                        @select(item.elementType){
                            @case 1:{ //输入框
                                <input type="text" name="${item.name}" id="${item.name}" autocomplete="off" maxlength="50" class="layui-input" ${isNotEmpty(item.verifyList)?('lay-verify="'+verifyFormat(item.verifyList)+'"'):''}>
                            @}
                            @case 2:{ //下拉框
                                <layui:simpleDataSelect name="${item.name}" value="\${has(${entity.code})?${entity.code}.${item.name}:''}" data="\${${item.name}List}"
                                            attrId="id" attrName="name" laySearch="true" />
                            @}
                            @case 3:{ //复选
                                <input type="checkbox" name="${item.name}" title="选项1">
                                <input type="checkbox" name="${item.name}" title="选项2">
                            @}
                            @case 4:{ //单选框
                                <input type="radio" name="${item.name}" value="1" title="是">
                                <input type="radio" name="${item.name}" value="0" title="否">
                            @}
                            @case 5:{ //文本域
                </div><!-- input-inline-->
            </div><!-- inline-->
        </div><!--form item-->
    </div><!--row-->
<div class="layui-row">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">${item.displayName}</label>
            <div class="layui-input-block" style="width:512px">
                <textarea name="${item.name}"  id="${item.name}" placeholder="请输入" class="layui-textarea" ${isNotEmpty(item.verifyList)?('lay-verify="'+verifyFormat(item.verifyList)+'"'):''}></textarea>
            </div>
        </div>
    </div>
</div>
<div class="layui-row">
    <div class="layui-form-item">
    @}
    @case 6:{ //日期
            <input type="text" name="${item.name}"  id="${item.name}" autocomplete="off" class="layui-input input-date" ${isNotEmpty(item.verifyList)?('lay-verify="'+verifyFormat(item.verifyList)+'"'):''}>
    @}
    @case 7:{ //图片
    </div><!-- input-inline-->
</div><!-- inline-->
</div><!--form item-->
</div><!--row-->
<layui:image id="${item.name}" tagName="${item.displayName}" tips="图片说明"/>

<div class="layui-row">
    <div class="layui-form-item">
                            @}
                            @case 8,9,10:{ //文件
    </div><!-- input-inline-->
</div><!-- inline-->
</div><!--form item-->
</div><!--row-->

<layui:singleFile id="${item.name}" tagName="${item.displayName}" tips="说明对文件的限制"/>

<div class="layui-row">
    <div class="layui-form-item">
    @}
                            @case 20:{ //静态文本
                                    <span style="line-height:38px;margin-left:8px">
                                        \${${entity.code}.${item.name}}
                                    </span>
                            @}
                        @}
					@}else{
					<layui:simpleDictSelect style='layui-input-inline' type="${item.dictType}" layVerify="${verifyFormat(item.verifyList)}"
								id="${item.name}" name="${item.name}" value="" />
					@}
                    @if(entity.pageType==3) {
                        <i class="layui-icon layui-icon-edit" id="${item.name}Edit" fieldName="${item.name}" style="font-size: 12px; color: #00CD66;"></i>
                        <i class="layui-icon layui-icon-ok layui-hide" id="${item.name}Ok"  fieldName="${item.name}" style="font-size: 12px; color: #00EE76;"></i>
                        <i class="layui-icon layui-icon-close-fill layui-hide" id="${item.name}Close" fieldName="${item.name}" style="font-size: 12px; color: #FF3030;"></i>
                    @}
                @}
				</div>
            </div>
		@}
        </div>
    </div>
	@}
	@if(entity.attachment){
    <div class="layui-row">
        <!-- 业务对象得有一个字段保存附件id，假设是attachmentId  -->
        <layui:attachment name="attachmentId" batchFileUUID="\${uuid()}"  bizType="entity.name" isNew="true"  />
    </div>
	@}
    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script>
@if(!isEmpty(hasImage)) {
    Common.initImage();
@}
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','${entity.code}Api'], function(exports) {
    var form = layui.form;
    var ${entity.code}Api = layui.${entity.code}Api;
    var index = layui.index;
    var isNew = true;
    <!--# if(!(isEmpty(${entity.code}Json))){  -->
    isNew = false;
    <!--# } -->
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
          @if(entity.pageType==3) {
            this.hideInputField();
          @}
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();
                form.on('submit(form)', function(){
                    ${entity.code}Api.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }
      @if(entity.pageType==3) {
        ,hideInputField:function() {
        }
      @}

    }
    view.init();
    <!--# if(!(isEmpty(${entity.code}Json))){  -->
    var formJson = \${${entity.code}Json};
    form.val("editform",formJson);
    @if(!isEmpty(hasImage)) {
    $(".image-preview").each(function() {
        $(this).attr("src",formJson[$(this).attr("id")]);
    });
    @}
    @if(!isEmpty(hasFile) && hasFile==2) {
    $(".file_link").each(function() {
        var a=document.createElement('a');
        var aJq = $(a);
        aJq.html("下载文件");
        aJq.attr("href",formJson[$(this).attr("id")]);
        aJq.attr("target","_blank");
        $(this).append(aJq);
    });
    @}
    <!--# } -->
});
</script>
